//-------------------------------------------------------------------------------------
//
// JGE++ is a hardware accelerated 2D game SDK for PSP/Windows.
//
// Licensed under the BSD license, see LICENSE in JGE root for details.
// 
// Copyright (c) 2007 James Hui (a.k.a. Dr.Watson) <jhkhui@gmail.com>
// 
//-------------------------------------------------------------------------------------

#include <stdio.h>

#include <JGE.h>
#include <JRenderer.h>
#include <JTTFont.h>
#include <Encoding.h>
#include "GameApp.h"
#include "HMap.h"


//-------------------------------------------------------------------------------------
// Constructor. Variables can be initialized here.
//
//-------------------------------------------------------------------------------------
GameApp::GameApp()
{
	mTTFont = NULL;
}


//-------------------------------------------------------------------------------------
// Destructor.
//
//-------------------------------------------------------------------------------------
GameApp::~GameApp()
{
}


//-------------------------------------------------------------------------------------
// This is the init callback function. You should load and create your in-game 
// resources here.
// 
//-------------------------------------------------------------------------------------
void GameApp::Create()
{

	//Load Font	
	mTTFont = new JTTFont();
	//mTTFont->Load("ZendaEmbossed.ttf", 32);		// size 32
	mTTFont->Load("fonts/simsun.ttc", 12);

	//Load Sprite;
	JRenderer* renderer = JRenderer::GetInstance();

	map = new HMap();

	mGirl = new HChar(renderer->LoadTexture("pics/Female/Eren.png"),32,48);
	
	mGirl->SetPosition(150,100);
	mGirl->SetDst(150,200);

}


//-------------------------------------------------------------------------------------
// This is the clean up callback function. You should delete all your in-game 
// resources, for example texture and quads, here.
// 
//-------------------------------------------------------------------------------------
void GameApp::Destroy()
{
	// Cleaning up
	if (mTTFont)
		delete mTTFont;

}


//-------------------------------------------------------------------------------------
// This is the update callback function and is called at each update frame
// before rendering. You should update the game logic here.
//
//-------------------------------------------------------------------------------------
void GameApp::Update()
{

	JGE* engine = JGE::GetInstance();

	// do a screen shot when the TRIANGLE button is pressed
	if (engine->GetButtonClick(PSP_CTRL_TRIANGLE))		
	{
		char s[80];

		// save screen shot to root of Memory Stick 
		sprintf(s, "ms0:/screenshot.png");			
		JRenderer::GetInstance()->ScreenShot(s);
	}

	// exit when the CROSS button is pressed
	if (engine->GetButtonClick(PSP_CTRL_CROSS))	
	{
		engine->End();
		return;
	}

	//////////Game Logic////////////////

	
	JSprite *g = mGirl->GetSprite();
	if(mGirl->IsMoving() == false) 
		mGirl->SetDst(400,200);
	mGirl->Update(0.5);


}


//-------------------------------------------------------------------------------------
// All rendering operations should be done in Render() only.
// 
//-------------------------------------------------------------------------------------
void GameApp::Render()
{
	// get JRenderer instance
	JRenderer* renderer = JRenderer::GetInstance();		
	renderer->EnableTextureFilter(false);
	// clear screen to black
	renderer->ClearScreen(ARGB(0,0,0,0));
	
	// set font colour
	mTTFont->SetColor(ARGB(255,0,255,0));	
	

	mGirl->GetSprite()->Render();

	JTexture* t = map->GetTexture(1);
	JQuad* q = new JQuad(t,0,0,t->mWidth,t->mHeight);
	renderer->RenderQuad(q,0,0);

	
}


//-------------------------------------------------------------------------------------
// This function is called when the system wants to pause the game. You can set a flag
// here to stop the update loop and audio playback.
//
//-------------------------------------------------------------------------------------
void GameApp::Pause()
{
	// we haven't had anything to do here yet
}


//-------------------------------------------------------------------------------------
// This function is called when the game returns from the pause state.
//
//-------------------------------------------------------------------------------------
void GameApp::Resume()
{
	// we haven't had anything to do here yet
}
